package com.hyts.serialize.json.fastjson;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.JSONSerializableSerializer;
import com.hyts.serialize.json.JsonSerializeHandler;

/**
 * project-name:coffice-toolbox
 * package-name:com.hyts.serialize.json.fastjson
 * author:Libo/Alex
 * create-date:2019-06-28 10:49
 * email:liboware@gmail.com
 * description:此类主要用于: fastjson服务对象操作处理器
 */
public class FastJsonSerializeHandler implements JsonSerializeHandler<JSONObject> {


    @Override
    public <P> JSONObject buildJSONObject(P param) {
        return JSON.parseObject(JSON.toJSONString(param));
    }

    @Override
    public <P> String buildJSONString(P param) {
        return JSON.toJSONString(param);
    }

    @Override
    public <P> JSONObject buildJSONObject(String jsonStr) {
        return JSONObject.parseObject(jsonStr);
    }

    @Override
    public <P> P buildBean(String jsonStr, Class<P> clazzType) {
        return JSONObject.parseObject(jsonStr,clazzType);
    }

    @Override
    public Object buildBean(String jsonStr) {
        return JSONObject.parse(jsonStr);
    }
}
